-
-
Notifications
You must be signed in to change notification settings - Fork 779
#1926 - elderberry #2369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1926 - elderberry #2369
Conversation
|
WalkthroughThe changes update the PrismaExtension to robustly support both single-file and directory-based Prisma schema configurations. The extension now detects whether the provided schema path is a directory or a file using Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/build/src/extensions/prisma.ts (2)
78-106
: Well-structured schema detection logic!The implementation correctly:
- Resolves paths relative to the working directory
- Provides detailed debug logging for troubleshooting
- Detects schema type (file vs directory) reliably
- Warns about missing
schema.prisma
in multi-file setupsConsider making the warning message at lines 101-103 more actionable by suggesting what the user should do:
- `PrismaExtension: The provided schema path is a directory (${this._resolvedSchemaPath}) but no schema.prisma was found inside. Ensure your multi-file schema folder contains a schema.prisma with datasource/generator blocks.` + `PrismaExtension: The provided schema path is a directory (${this._resolvedSchemaPath}) but no schema.prisma was found inside. Please create a schema.prisma file with datasource/generator blocks in this directory for multi-file schema to work correctly.`
133-133
: Simplify boolean conversionThe
Boolean()
wrapper is unnecessary since_schemaIsDirectory
is already typed as boolean.- const schemaIsDirectory = Boolean(this._schemaIsDirectory); + const schemaIsDirectory = this._schemaIsDirectory ?? false;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/build/src/extensions/prisma.ts
(6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)
**/*.{ts,tsx}
: Always prefer using isomorphic code like fetch, ReadableStream, etc. instead of Node.js specific code
For TypeScript, we usually use types over interfaces
Avoid enums
No default exports, use function declarations
Files:
packages/build/src/extensions/prisma.ts
🧠 Learnings (12)
📓 Common learnings
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T17:49:24.468Z
Learning: Applies to internal-packages/database/**/*.{ts,tsx} : We use prisma in internal-packages/database for our database interactions using PostgreSQL
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When implementing schema tasks, use `schemaTask` from `trigger.dev/sdk/v3` and validate payloads as shown.
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to trigger.config.ts : Build extensions such as `additionalFiles`, `additionalPackages`, `aptGet`, `emitDecoratorMetadata`, `prismaExtension`, `syncEnvVars`, `puppeteer`, `ffmpeg`, and `esbuildPlugin` must be configured in `trigger.config.ts` as shown.
📚 Learning: applies to internal-packages/database/**/*.{ts,tsx} : we use prisma in internal-packages/database fo...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T17:49:24.468Z
Learning: Applies to internal-packages/database/**/*.{ts,tsx} : We use prisma in internal-packages/database for our database interactions using PostgreSQL
Applied to files:
packages/build/src/extensions/prisma.ts
📚 Learning: applies to trigger.config.ts : build extensions such as `additionalfiles`, `additionalpackages`, `ap...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to trigger.config.ts : Build extensions such as `additionalFiles`, `additionalPackages`, `aptGet`, `emitDecoratorMetadata`, `prismaExtension`, `syncEnvVars`, `puppeteer`, `ffmpeg`, and `esbuildPlugin` must be configured in `trigger.config.ts` as shown.
Applied to files:
packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : when implementing schema tasks, use `schematask` from `...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When implementing schema tasks, use `schemaTask` from `trigger.dev/sdk/v3` and validate payloads as shown.
Applied to files:
packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : always generate trigger.dev tasks using the `task` func...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : ALWAYS generate Trigger.dev tasks using the `task` function from `trigger.dev/sdk/v3` and export them as shown in the correct pattern.
Applied to files:
packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : you must use `@trigger.dev/sdk/v3` when writing trigger...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : You MUST use `trigger.dev/sdk/v3` when writing Trigger.dev tasks.
Applied to files:
packages/build/src/extensions/prisma.ts
📚 Learning: before generating any code for trigger.dev tasks, verify: (1) are you importing from `@trigger.dev/s...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Before generating any code for Trigger.dev tasks, verify: (1) Are you importing from `trigger.dev/sdk/v3`? (2) Have you exported every task? (3) Have you generated any deprecated code patterns?
Applied to files:
packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : you must `export` every task, including subtasks, in tr...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : You MUST `export` every task, including subtasks, in Trigger.dev task files.
Applied to files:
packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : tasks must be exported, even subtasks in the same file....
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Tasks must be exported, even subtasks in the same file.
Applied to files:
packages/build/src/extensions/prisma.ts
📚 Learning: applies to apps/webapp/**/*.{ts,tsx} : when importing from `@trigger.dev/core` in the webapp, never ...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/webapp.mdc:0-0
Timestamp: 2025-07-18T17:49:47.180Z
Learning: Applies to apps/webapp/**/*.{ts,tsx} : When importing from `trigger.dev/core` in the webapp, never import from the root `trigger.dev/core` path; always use one of the subpath exports as defined in the package's package.json.
Applied to files:
packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : the `run` function contains your task logic in trigger....
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : The `run` function contains your task logic in Trigger.dev tasks.
Applied to files:
packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : when triggering a task from backend code, use `tasks.tr...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When triggering a task from backend code, use `tasks.trigger`, `tasks.batchTrigger`, or `tasks.triggerAndPoll` as shown in the examples.
Applied to files:
packages/build/src/extensions/prisma.ts
🔇 Additional comments (6)
packages/build/src/extensions/prisma.ts (6)
4-4
: LGTM!The addition of
statSync
is appropriate for detecting whether the schema path is a directory.
59-59
: LGTM!The private property correctly stores the schema type for later use.
148-183
: Excellent typedSql handling!The implementation:
- Correctly determines the SQL base directory based on schema type
- Includes proper error handling and existence checks
- Provides detailed debug logging for troubleshooting
- Gracefully handles missing SQL directories
185-216
: Well-implemented multi-file schema support!The logic correctly:
- Identifies and copies all
.prisma
files from the schema directory- Uses the explicit
--schema=./prisma/schema
flag for Prisma CLI- Maintains the schema structure in the build output
217-235
: Consistent single-file schema handling!The implementation properly:
- Copies the single schema file to the standard location
- Uses explicit
--schema=./prisma/schema.prisma
flag for clarity- Includes debug logging for troubleshooting
239-267
: Robust migrations handling!The implementation excellently:
- Checks for migrations directory existence before attempting operations
- Uses the correct
--schema
flag based on schema type- Provides clear warnings when migrations are expected but missing
- Prevents errors by skipping migrate deploy when no migrations exist
Likely causes of problems in 6.6.0+
schema/
instead of next toschema.prisma
.output
path and may not write tonode_modules
in certain setups.prisma.config.ts
not being considered could misalign schema/migration paths vs what the CLI uses.package.json.prisma.schema
overrides not considered by our logic.schema
.Most likely root causes: missing
--schema
for multi-file schemas, and wrong migrations folder resolution when the main schema lives insideschema/
.Changes implemented in
packages/build/src/extensions/prisma.ts
options.schema
resolves to a file or a directory usingstatSync
.--schema
explicitly:--schema=./prisma/schema
--schema=./prisma/schema.prisma
<schemaDir>/migrations
<dirname(file)>/migrations
migrate deploy
if migrations exist, and include the same--schema
flag.<schemaDir>/sql
(folder schema) or<dirname(file)>/sql
(file schema), if present.You can review the important edits here:
How to validate quickly
--schema
flag (directory or file).sql/
dir.Interim guidance for users on Prisma 6.6.0 (multi-file schema)
Put
schema.prisma
and your other.prisma
files together inprisma/schema
(or any folder) and pass that folder path toprismaExtension({ schema: "<that-folder>" })
, or pass the file path if you use a single-file schema.Ensure
migrations
sits next to the file that definesdatasource
(i.e., next toschema.prisma
if that’s your main).If you keep a folder schema, prefer configuring your
package.json
prisma.schema
to point at the folder (the extension now passes--schema
itself, but the package.json field helps your local tooling).If you’re using the new
prisma-client
generator, ensure your imports match its output path and bundling setup.I didn’t change our API surface (still
prismaExtension({ schema: ... })
), but it now handles both files and directories correctly and avoids old assumptions.Next step (optional): Add first-class
prisma.config.ts
support by copying and rewriting it for the build layer or by parsing it to honor customschema
,migrations.path
, andtypedSql.path
. For now, explicit--schema
and correct folder copying should unblock most 6.6.0 setups.If you hit issues in a specific repo, share your
prismaExtension
call, schema layout, and whether you’re usingprisma-client-js
or the newprisma-client
generator, and we can wire in explicit handling as needed.Updated
packages/build/src/extensions/prisma.ts
to:schema
--schema
in both generate and migrate commandsNo linter errors in the file after edits
Typecheck for the whole package fails due to cross-package types (unrelated to this change)